#include <iostream>
#include <vector>
#include "thread.hpp"
using namespace ThreadModule;
using namespace std;
int g_tickets = 10000;

void route(int &tickets)
{
    while (true)
    {
        if (tickets > 0)
        {
            usleep(1000);
            printf("get tickets:%d\n", tickets);
            tickets--;
        }
        else
        {
            break;
        }
    }
}

const int num = 4;
int main()
{
    vector<Thread<int>> threads;
    for (int i = 0; i < num; i++)
    {
        string name = "thread-" + to_string(i + 1);
        threads.emplace_back(route, g_tickets, name);
    }

    for (auto &thread : threads)
    {
        thread.start();
    }
    for (auto &thread : threads)
    {
        thread.join();
        cout << "wait thread done,thread is:" << thread.name() << endl;
    }
    return 0;
}